/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is MaoBot.
 *
 * The Initial Developer of the Original Code is NoobSauce <tvilece@gmail.com>.
 * Portions created by NoobSauce are Copyright (C) 2011 NoobSauce. All Rights Reserved.
 *
 * Contributor(s):
 * tankgunk <tankgunk@gmail.com>
 *
 * ***** END LICENSE BLOCK ***** */
package org.maobot;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Pile {
	public ArrayList<Card> arrangement;
	static Card[] stdeck;
	Pile(){//Normal piles start out empty.
		arrangement = new ArrayList<Card>(0);
	}
	public int size(){//Checks size of a pile.
		return arrangement.size();
	}
	public Card lookAt(int i){//Don't use this to move a card, use send.
		return (arrangement.get(i));
	}
	public Card[] lookRange(int start, int end){//Non-destructive.
		return (Card[])arrangement.subList(start, end).toArray();
	}
	public Card[] sendRange(int start, int end){//Destructive.
		Card[] temp = (Card[])arrangement.subList(start, end).toArray();
		for(int i = 0; i <= (start-end); i++){
			arrangement.remove(start);
		}
		return temp;
	}
	public Card[] putRange(int insert, Card[] c){//Inserts cards in order, keeping other cards
		arrangement.addAll(insert, Arrays.asList(c));
		return c;
	}
	public Card add(Card c){//Shows card for proof that it worked
		arrangement.add(c);
		return c;
	}
	public Card add(int i, Card c){//add to index i.
		arrangement.add(i, c);
		return c;
	}
	public Card addTop(Card c){//Add to the top of the pile
		arrangement.add(0, c);
		return c;
	}
	public Card addBottom(Card c){//Add to the bottom of the pile
		arrangement.add(c);
		return c;
	}
	public Card[] addAll(Pile p){//Merge another pile into the bottom of this pile.
		Card[] t = (Card[])p.arrangement.toArray();
		arrangement.addAll(Arrays.asList(t));
		p.arrangement.clear();
		return t;
	}
	public Card send(int i){//should only be used when the Card is going to be read
		return (arrangement.remove(i));
	}
	public void shuffle(){
		Collections.shuffle(arrangement);
	}
	public void shuffleIn(Card c){
		arrangement.add(c);
		shuffle();
	}
	public void shuffleIn(Pile d){
		arrangement.addAll(d.arrangement);
		d.arrangement = null;
		shuffle();
	}
}
